<template>
    <reply-item v-if="reply" :reply="reply" @reloadReply="goToPush" management></reply-item>
</template>

<script>
    import ReplyItem from '@/components/postReply/ReplyItem'
    import { mapActions } from 'vuex'

    export default {
        name: 'reply',
        components: {
            ReplyItem
        },
        data () {
            return {
                reply: null
            }
        },
        mounted () {
            let replyId = this.getReplyId()
            this.action(this.getByIdAction(replyId), data => {
                let reply = data.data
                if (reply.storey) {
                    this.action(this.listStoreyAction(replyId), data => {
                        reply.storeys = data.data
                        this.reply = reply
                    })
                } else {
                    this.reply = reply
                }
            })
        },
        methods: {
            ...mapActions({
                getByIdAction: 'reply/getById',
                listStoreyAction: 'storey/listStorey'
            }),
            getReplyId () {
                let paths = this.$route.path.split('/')
                return paths[paths.length - 1]
            },
            goToPush () {
                this.$router.push(`/push`)
            }
        }
    }
</script>

<style scoped>

</style>
